<!DOCTYPE html>
<html lang="ru">
<head>
	<title>QUnit Tests</title>
    <meta charset="utf-8" />
	



  <script src="/js/modernizr-2.0.6.min.js"></script>
  <link rel="stylesheet" href="/css/style.css" media="screen">
  <link rel="stylesheet" href="/css/layout.css" media="screen">
  <script src="/js/jq1.7.js"></script>

 <script type="text/javascript">
        	(function fire(){
				
				this.ajax = function(url, data, getData){
					$.ajax({
						'url': url,
						'data' : data,
						'type': 'POST',
						'dataType': 'json',
						'success' : getData
					});
				};
				
				this.request = function(){
					
					t.ajax("newRequest.php","Route=2406MOWLON&AD=1&CN=0&CS=E&Partner=testapic&_Serialize=JSON", function(data){
						
						if(!data.Error){
							var dataID = data.ID;
							
							t.ajax("requestState.php","R=" +data.ID + "&_Serialize=JSON", function(data){
								
									if(!data.Error){
										if(data.Completed == 100){
											
											t.ajax("fares.php","R=" + dataID + "&V=Matrix&VB=true&L=ru&_Serialize=JSON", function(data){
												if(!data.Error){
													
													t.dataObj = data;
													t.show();
												}
											})
										}				
									}
							})
						}
					});
					
				};
				
				this.show = function(){
					
				//	console.log(t.dataObj)
					
					
					var strMenu = "";
					
					for(var i=0; i<t.dataObj.Airlines.length; i++){
						var aName = "";
						if(i==0) {
							aName = "class='current'";
					//		t.activeAirline = t.dataObj.Airlines[i].Code;
						}
						
						strMenu += "<li id='" + t.dataObj.Airlines[i].Code + "' " + aName+ ">" + t.dataObj.Airlines[i].Name + "</li>";
					}
					t.menu = $("menu");
					t.menu.html(strMenu);
					t.addAction();
					t.showFares();
					
				};
				
				this.showFares = function(){
					
					 
					if($(this).index()!=-1){
						t.activeAirline = $(this).index();
						t.menu.find("li").removeClass("current");
						$(this).addClass("current"); 
						
					}
					console.log(t.dataObj);
					 var ff = t.dataObj.Airlines[t.activeAirline].FaresFull[0];
					 


					//console.log(ff);
						
							
							
						for(var j=0; j < ff.Directions.length; j++){
							
								var ssDS = ff.Directions[j].Segments[0].Trips;
								
							
													
									var tr = "";
									for(var g=0; g < ssDS.length; g++){
										
										var dd = ssDS[g].Departure.Date, ad = ssDS[g].Arrival.Date;
										dd = (dd == ad)? new Date(dd) : dd - ad;
										
										var mm = ((parseInt(dd.getMonth())+1)<10)?
													 "0" +(parseInt(dd.getMonth())+1):
													 parseInt(dd.getMonth())+1;
										 
										 tr += "<tr><td>" +
										 	 dd.getDate() + "." + mm + "." + dd.getYear() +
										 "</td><td>" +
											ssDS[g].Departure.City + "<br>" +
											
											ssDS[g].Departure.Time +
										"</td><td>" +
											ssDS[g].Arrival.City + "<br>" +
											 
											ssDS[g].Arrival.Time +
										"</td><td>" +
											ssDS[g].FlightNumber +
										"</td><td>" +
											ssDS[g].Departure.Airport +
										"</td><td>" +	
											ff.TotalAmount +
										"</td><tr>";
										
										
									}
									
							
							
							
							}
						
						
						
					$("section.content").html("<table><tr><th>Дата</th><th>Вылет</th><th>Прибытие</th><th>№ рейса</th><th>Аэропорт</th><th>Цена</th></tr>" + tr + "</table>");
					
					
					
				};
				
				this.addAction = function(){
					
					$("menu li").bind("click", t.showFares)
				};
				
				
				var t = this,
				init = function(){
					t.dataObj = {};
					t.activeAirline = 0;
					t.request();
				}()	
				
			})()
 </script>
        
<script type="text/javascript">
/*(function load(){
	console.log(navigator);

	function xxx(position){
	//	console.log(position.c);
		
		console.log(position);
		
	}
	function yyy(){
		console.log(navigator);
	}
	if(navigator.geolocation){
		navigator.geolocation.getCurrentPosition(xxx, yyy)	
	}
	
	
})();
*/
</script>

</head>
<body>
	<!-- section class="layout" -->
	    
      <menu>
        	<li>Культура</li>
            <li>Jack Daniel's. Новогоднее</li>
            <li>Политика</li>
            <li>Здоровье и молодость</li>
            <li>Дети</li>
	    </menu>
          <aside>
			<h2><strong>Популярные</strong>Записи</h2>
			<ul>
				<li>
					<a href="/profile/9402/blog/45130" class="underline"><span class="userInSubject">Александр Голб:</span> <br/>Сударьство это я!</a>
					<div class="meta">Вчера  </div>
				</li>
				<li>
					<a href="/profile/9402/blog/44831" class="underline"><span class="userInSubject">Александр Дфарб:</span> <br/>Сласть сыграть на опережение</a>
					<div class="meta">28.12.11  </div>
				</li>
				<li>
					<a href="/profile/9402/blog/43193" class="underline">Как Заяц отнимал у меня: рассказ Березы</a>
					<div class="meta">15.11.11  </div>
				</li>
              </ul>
	    </aside>
        <section class="content">
            
	    </section>
        
     
        
    <!-- /section -->
    <footer>dfgdfgdg</footer>
</body>
</html>
